/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import POJO.GiaVePoJo;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author tran quoc thinh
 */
public class GiaVeDAO {
    
    //Lấy giá vé theo từng giờ của rạp
    public ArrayList<GiaVePoJo> DSGiaVe()
    {
        ArrayList<GiaVePoJo> arr = new ArrayList<GiaVePoJo>();
        try
        {
            ResultSet rs;
            MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
            String sql = "select * from giave";
            dahp.Open();
            rs = dahp.excecuteQuery(sql);
            while (rs.next())
            {
                GiaVePoJo gv = new GiaVePoJo();                
                gv.setD2truoc12h(rs.getDouble("2dtruoc12h"));
                gv.setD212h18h(rs.getDouble("2d12h18h"));
                gv.setD218h21h(rs.getDouble("2d18h21h"));
                gv.setD221h(rs.getDouble("2d21h"));
                gv.setD321h(rs.getDouble("3dtruoc12h"));
                gv.setD312h18h(rs.getDouble("3d12h18h"));
                gv.setD318h21h(rs.getDouble("3d18h21h"));
                gv.setD321h(rs.getDouble("3d21h"));
                arr.add(gv);
            }
            dahp.Close();
        }
        catch(Exception ex)
        {
            
        }
        return arr;
    }
    
    //Cập nhật giá vé 
    public static int UpdateGiaVe(GiaVePoJo gv)
    {
        try{
            MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
            String sql = "update giave set 2dtruoc12h = "+gv.getD2truoc12h()+", 2d12h18h = "+gv.getD212h18h()+", 2d18h21h = "+gv.getD218h21h()+", 2d21h = "+gv.getD221h()+", 3dtruoc12h = "+gv.getD3truoc12h()+", 3d12h18h = "+gv.getD312h18h()+", 3d18h21h = "+gv.getD318h21h()+", 3d21h = "+gv.getD321h()+" where idgiave = "+ gv.getIdgiaVe();
            dahp.Open();
            dahp.excecuteUpdate(sql);
            dahp.Close();
            return 1;
        }
        catch(Exception ex)
        {
            return 0;
        }
    }
    
    public static ResultSet LayGiaVe()
    {
       try
        {
            ResultSet rs;
            MySQLDataAccessHelper dahp = new MySQLDataAccessHelper();
            dahp.Open();
            String sql = "select * from giave";
            rs = dahp.excecuteQuery(sql);        
            return rs;
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());            
        }
        return null;    
    }
}
